***** Parents impact with full sample, including spillover population

* 0. Read in data 

use "${dataanalysis}\ParentsReplication.dta", clear

* 1. globals
rename (mangroves_6 manclimate manbiodiv manconsume mangroves_6_1_index) (y1 y2 y3 y4 y5) // mangrove attitudes
rename (env_att_2 env_att_3 env_att_5_zero env_att_7_zero env_att_11_pos env_att_8_pos env_concern_index2z) (a1 a2 a3 a4 a5 a6 a7) // general environmental attitudes
rename (mangroves_3 mangroves_15 mangroveproj_rank mangroves_1_neg mangroves_1_nat mangroves_1_tour) (m1 m2 m3 m4 m5 m6) // mangrove attitudes

rename  (behavior_2_pos  behavior_3  behavior_4 behavior_6_pos behavior_z) (b1 b2 b3 b4 b5) // behaviors


global envknowledge y1 y2 y3 y4 y5  
global envatt a1 a2 a3 a4 a5 a6 a7
global manatt m1 m2 m3 m4 m5 m6
global envbehav b1 b2 b3 b4 b5 
global summarytable y5 a7 m3 b5 

* recoding negative things to positive for interpretation

recode m1 m2 (0=1) (1=0)

* generating interactions

g treatrisk = envrisk_zscore*treatindiv
g treattime = timesincetreatment*treatindiv
g treatgender = dem_gender*treatindiv

drop if parentattrite == 1
drop if nobaseline == 1
xtset id_p 


* 2. knowledge table

if 1{
estimates clear

foreach var in $envknowledge {
  preserve
  bysort id_p: egen bal`var' = count(`var')
  keep if bal`var' == 2 	 
  eststo xtr_`var': xtreg `var' treatindiv post control50 control75, fe nonest vce(cluster club_id)
  eststo xtrtime1_`var': xtreg `var' treatindiv post treattime control50 control75, fe nonest vce(cluster club_id)
  eststo xtrgen1_`var': xtreg `var' treatindiv post treatgender control50 control75, fe nonest vce(cluster club_id)
  eststo xtrrisk1_`var': xtreg `var' treatindiv post treatrisk envrisk_zscore control50 control75, fe nonest vce(cluster club_id)
  sum `var' if post == 0 
  local ymeanboys = round(r(mean),0.01)
  estadd scalar s1 `ymeanboys':  xtr_`var'
  sum `var'
  local obs = r(N) 	
  estadd scalar o1 `obs': xtr_`var'
  restore
}
 		
esttab xtr_y1 xtr_y2 xtr_y3 xtr_y4 xtr_y5 using "$tables/parentsknowledgefull.tex", replace se nonotes noobs style(tex) ///
 scalar("s1 Mean baseline"  "o1 Observations") sfmt(%12.3f %12.0f) b(%12.3f) se(%12.3f) ///
keep(treatindiv control50 control75) nolines ///
coeflabels(treatindiv "Treated" control50 "Spillover, 50\%" control75 "Spillover, 75\%") nolines collabels(none) ///
		starlevels(* 0.10 ** 0.05 *** 0.01) label nomtitles ///
		nonumbers  fragment  ///
		prehead( ) ///
		posthead(\\ \midrule \\) ///
		prefoot() ///
		postfoot()

}

		
* 3. Env attitudes table
estimates clear 

if 1{
	
estimates clear

foreach var in $envatt {
  preserve
  bysort id_p: egen bal`var' = count(`var')
  keep if bal`var' == 2 	
  eststo xtr_`var': xtreg `var' treatindiv post control50 control75, fe nonest vce(cluster club_id)
  eststo xtrtime1_`var': xtreg `var' treatindiv post treattime control50 control75, fe nonest vce(cluster club_id)
  eststo xtrgen1_`var': xtreg `var' treatindiv post treatgender control50 control75, fe nonest vce(cluster club_id)
  eststo xtrrisk1_`var': xtreg `var' treatindiv post treatrisk envrisk_zscore control50 control75, fe nonest vce(cluster club_id)
  sum `var' if post == 0 
  local ymeanboys = round(r(mean),0.01)
  estadd scalar sb `ymeanboys':  xtr_`var'
  sum `var'
  local obs = r(N) 	
  estadd scalar o1 `obs': xtr_`var'
  restore
}


		
esttab xtr_a1 xtr_a2 xtr_a3 xtr_a4 xtr_a5 xtr_a6 xtr_a7 using "$tables/parentsattitudefull.tex", replace se nonotes noobs style(tex) ///
 scalar("s1 Mean baseline"  "o1 Observations") sfmt(%12.3f %12.0f) b(%12.3f) se(%12.3f) ///
keep(treatindiv control50 control75) nolines ///
coeflabels(treatindiv "Treated" control50 "Spillover, 50\%" control75 "Spillover, 75\%") nolines collabels(none) ///
		starlevels(* 0.10 ** 0.05 *** 0.01) label nomtitles ///
		nonumbers  fragment  ///
		prehead( ) ///
		posthead(\\ \midrule \\) ///
		prefoot() ///
		postfoot()

}

* 4. Mangrove attitudes table

if 1{
	
estimates clear


foreach var in $manatt  {
  preserve
  bysort id_p: egen bal`var' = count(`var')
  keep if bal`var' == 2 	
  eststo xtr_`var': xtreg `var' treatindiv post control50 control75, fe nonest vce(cluster club_id)
  eststo xtrtime1_`var': xtreg `var' treatindiv post treattime control50 control75, fe nonest vce(cluster club_id)
  eststo xtrgen1_`var': xtreg `var' treatindiv post treatgender control50 control75, fe nonest vce(cluster club_id)
  eststo xtrrisk1_`var': xtreg `var' treatindiv post treatrisk envrisk_zscore control50 control75, fe nonest vce(cluster club_id)
  sum `var' if post == 0 
  local ymeanboys = round(r(mean),0.01)
  estadd scalar s1 `ymeanboys':  xtr_`var'
  sum `var'
  local obs = r(N) 	
  estadd scalar o1 `obs': xtr_`var'
  restore
}

		
esttab xtr_m1 xtr_m2 xtr_m3 xtr_m4 xtr_m5 xtr_m6  using "$tables/parentsmanattfull.tex", replace se nonotes noobs style(tex) ///
 scalar("s1 Mean baseline"  "o1 Observations") sfmt(%12.3f %12.0f) b(%12.3f) se(%12.3f) ///
keep(treatindiv control50 control75) nolines ///
coeflabels(treatindiv "Treated" control50 "Spillover, 50\%" control75 "Spillover, 75\%") nolines collabels(none) ///
		starlevels(* 0.10 ** 0.05 *** 0.01) label nomtitles ///
		nonumbers  fragment  ///
		prehead( ) ///
		posthead(\\ \midrule \\) ///
		prefoot() ///
		postfoot()

}


* 5. Behaviors table

if 1{	
estimates clear


foreach var in $envbehav {
  preserve
  bysort id_p: egen bal`var' = count(`var')
  keep if bal`var' == 2	
  eststo xtr_`var': xtreg `var' treatindiv post control50 control75, fe nonest vce(cluster club_id)
  eststo xtrtime1_`var': xtreg `var' treatindiv post treattime control50 control75, fe nonest vce(cluster club_id)
  eststo xtrgen1_`var': xtreg `var' treatindiv post treatgender control50 control75, fe nonest vce(cluster club_id)
  eststo xtrrisk1_`var': xtreg `var' treatindiv post treatrisk envrisk_zscore control50 control75, fe nonest vce(cluster club_id)
  sum `var' if post == 0 
  local ymeanboys = round(r(mean),0.01)
  estadd scalar s1 `ymeanboys':  xtr_`var'
  sum `var'
  local obs = r(N) 	
  estadd scalar o1 `obs': xtr_`var'
  restore
}

		
esttab xtr_b1 xtr_b2 xtr_b3 xtr_b4 xtr_b5 using "$tables/parentsbehavfull.tex", replace se nonotes noobs style(tex) ///
 scalar("s1 Mean baseline"  "o1 Observations") sfmt(%12.3f %12.0f) b(%12.3f) se(%12.3f) ///
keep(treatindiv control50 control75) nolines ///
coeflabels(treatindiv "Treated" control50 "Spillover, 50\%" control75 "Spillover, 75\%") nolines collabels(none) ///
		starlevels(* 0.10 ** 0.05 *** 0.01) label nomtitles ///
		nonumbers  fragment  ///
		prehead( ) ///
		posthead(\\ \midrule \\) ///
		prefoot() ///
		postfoot()

}	

